/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import EntityBeans.Client;
import SessionBeans.ClientFacadeLocal;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import obj.Md5;

/**
 *
 * @author Nascotix
 */
@ManagedBean(name="CreateAccount" ) 
@RequestScoped
public class CreateAccount {
        @EJB
        private ClientFacadeLocal clientFacade;
        
        private String nom;
        private String prenom;
        private String civilite = "M";
        private String email;
        private String adresse;
        private String cp;
        private String box;
        private String ville;
        private String tel;
        private String pwd_1;
        private String pwd_2;

        public String getNom() {
            return nom;
        }
        public void setNom(String nom) {
            this.nom = nom;
        }
        public String getPrenom() {
            return prenom;
        }
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
        public String getCivilite() {
            return civilite;
        }
        public void setCivilite(String civilite) {
            this.civilite = civilite;
        }
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
        public String getAdresse() {
            return adresse;
        }
        public void setAdresse(String adresse) {
            this.adresse = adresse;
        }
        public String getCp() {
            return cp;
        }
        public void setCp(String cp) {
            this.cp = cp;
        }
        public String getBox() {
            return box;
        }
        public void setBox(String box) {
            this.box = box;
        }
        public String getVille() {
            return ville;
        }
        public void setVille(String ville) {
            this.ville = ville;
        }
        public String getTel() {
            return tel;
        }
        public void setTel(String tel) {
            this.tel = tel;
        }
        public String getPwd_1() {
            return pwd_1;
        }
        public void setPwd_1(String pwd_1) {
            this.pwd_1 = pwd_1;
        }
        public String getPwd_2() {
            return pwd_2;
        }
        public void setPwd_2(String pwd_2) {
            this.pwd_2 = pwd_2;
        }
               
    /**
     * Creates a new instance of CreateAccount
     */
    public String NewClient(){ 
        Client client = new Client();
        Md5 passmd5 = new Md5();
        client.setName(nom);
        client.setFirstname(prenom);
        client.setCivility(civilite);
        client.setAddress(adresse);
        client.setCp(cp);
        client.setCity(ville);
        client.setBox(box);
        //System.out.println(passmd5.convert(pwd_1));
        client.setPassword(passmd5.convert(pwd_1));
        client.setEmail(email);
        client.setPhone(tel);
        
        clientFacade.create(client);
        System.out.println(client);
        return "Valid-NewAccount.xhtml";  
    } 
}
